﻿using Entity;
using Microsoft.Extensions.Configuration;
using ServiceCore.Tool.Post;
using System;
using System.Collections.Generic;
using System.Text;

namespace ServiceCore.Tool.Wx.diy_menu
{
    public interface Idiy_menu_service
    {
        /// <summary>
        /// 设置菜单
        /// </summary>
        /// <param name="subdata"></param>
        /// <returns></returns>
        diy_menu_create_result diy_menu_create(menu_create_params subdata);
        diy_menu_search_result diy_menu_get();
    }
    public class diy_menu_service: Idiy_menu_service
    {
        private readonly IConfiguration AppSettingConfig;
        public diy_menu_service(IConfiguration configuration)
        {
            AppSettingConfig = configuration;
        }
        public string get_access_token_api_url { get { return AppSettingConfig["get_access_token_api"]; } }
        /// <summary>
        /// 获取accesstoken
        /// </summary>
        private string get_accesstoken
        {
            get
            {
                string access_token = Http_Helper.HttpGet(get_access_token_api_url + $"?who=rk_{DateTime.Now.ToString("yyyy-MM:dd")}");
                if (access_token == "小朋友，你是不是有许多问号")
                {
                    access_token = "";
                }
                return access_token;
            }
        }

        /// <summary>
        /// 保存菜单信息
        /// </summary>
        public diy_menu_create_result diy_menu_create(menu_create_params subdata)
        {
            diy_menu_create_result wx_result = new api_base().create_option(diy_menu_config.Api_Url.create, get_accesstoken).http_client<menu_create_params, diy_menu_create_result>(subdata, false);
            return wx_result;
        }  
        /// <summary>
        /// 查询当前自定义菜单
        /// </summary>
        /// <param name="subdata"></param>
        /// <returns></returns>
        public diy_menu_search_result diy_menu_get()
        {
            diy_menu_search_result wx_result = new api_base().create_option(diy_menu_config.Api_Url.get_current_selfmenu_info, get_accesstoken).http_client<menu_create_params, diy_menu_search_result>(null);
            return wx_result;
        }

         

    }
}
